﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Kokomo.Xml
{
	public abstract class NamespaceSchema
	{
		public NamespaceSchema(string name, Uri uri)
		{
			this.Name = name;
			this.Uri = uri;
			this.Overrides = new TypeSchemaCollection();
		}

		public string Name { get; private set; }
		public Uri Uri { get; private set; }
		public TypeSchemaCollection Overrides { get; private set; }

		public TypeSchema GetTypeSchema(Type type)
		{
			ArgumentValidation.CheckNullArgument("type", type);

			TypeSchema schema = this.Overrides.FindByType(type);
			if (schema == null)
			{
				schema = this.GetTypeSchemaCore(type);
			}

			return schema;
		}
		protected abstract TypeSchema GetTypeSchemaCore(Type type);

		public TypeSchema GetTypeSchema(string elementName)
		{
			ArgumentValidation.CheckNullArgument("elementName", elementName);

			TypeSchema schema = this.Overrides.FindByElementName(elementName);
			if (schema == null)
			{
				schema = this.GetTypeSchemaCore(elementName);
			}
			return schema;
		}
		protected abstract TypeSchema GetTypeSchemaCore(string elementName);
	}
}
